#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int P[maxn];
bool vis[maxn];
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int N; cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> P[i];
    }
    memset(vis, 0, sizeof(vis));
    vector<int> v;
    for (int i = 1; i <=N ; ++i) if(!vis[i]) {
        vis[i] = true;
        int t = P[P[t]];
        vis[t] = true;
        int cnt = 1;
        while (t != i) {
            ++cnt;
            t = P[P[t]];
            vis[t] = true;
            v.push_back(cnt);
        }
    }
    for(auto &it:v) cout << it << " ";

    return 0;
}